window.onload=function(){
			$(":radio[name='type']").bind('click',function(){
				if(this.checked){
					var left=33,right=16;
					switch(parseInt(this.value)){
					case 1:left=33;right=16;break;
					case 2:left=35;right=12;break;
					case 3:left=30;right=30;break;
					default:left=33;right=16;break;
					}
					selectNums(left,right);
				}
			});
			selectNums(33,12);
			function selectNums(left,right){
				$("#left")[0].length=0;
				for(var i=1;i<=left;i++){
					$("#left").append("<option value='"+i+"'>"+i+"</option>");
				}
				$("#right")[0].length=0;
				for(var i=1;i<=right;i++){
					$("#right").append("<option value='"+i+"'>"+i+"</option>");
				}
				if(left==33){
					$("#left").val(6);
					$("#right").val(1);
				}else if(left==35){
					$("#left").val(5);
					$("#right").val(2);
				}else if(left==30){
					$("#left").val(6);
					$("#right").val(1);
				}
			}
			var redSet=new HashSet();
			var blueSet=new HashSet();		
			var redRemain=new HashSet();
			var blueRemain=new HashSet();
			var redArea=document.getElementById("redArea");
			var blueArea=document.getElementById("blueArea");
			var filter=document.getElementById("filter");			
			//alert(leftSrc.cols+","+leftSrc.rows);
			function filterAction(){
				redSet.empty();
				blueSet.empty();
				redRemain.empty();
				blueRemain.empty();
				var arr=$.trim(leftSrc.value).split("\n");
				for(var i=0;i<arr.length;i++){					
					if(arr[i].replace(/ /g,"")=="") continue;
					var red=$.trim(arr[i].split("|")[0]).indexOf(",")>0?$.trim(arr[i].split("|")[0]).split(","):$.trim(arr[i].split("|")[0]).split(" ");				
					var blue=$.trim(arr[i].split("|")[1]).indexOf(",")>-1?$.trim(arr[i].split("|")[1]).split(","):$.trim(arr[i].split("|")[1]).split(" ");
					for(var e=0;e<red.length;e++){
						redSet.add($.trim(red[e]));	
					}
					for(var e=0; e<blue.length;e++){
						blueSet.add($.trim(blue[e]));	
					}					
				}
				//console.log(redSet.toArray().toString()+"__"+blueSet.toArray().toString());
				//$(redArea).attr("value",redSet.toArray().toString());
				//$(blueArea).attr("value",blueSet.toArray().toString());
				//alert(blueArea.innerText+"_"+blueArea.innerHTML);
				//redArea.setAttribute("value",redSet.toArray().toString());
				//blueArea.setAttribute("value",blueSet.toArray().toString());
				redArea.value=redSet.toArray().toString();
				blueArea.value=blueSet.toArray().toString();
				var typeValue=$(":radio[checked]").attr("value");
				var left=33,right=16;
				switch(parseInt(typeValue)){
				case 1:left=33;right=16;break;
				case 2:left=35;right=12;break;
				case 3:left=30;right=30;break;
				default:left=33;right=16;break;
				}
				for(var i=1;i<=left;i++){
					redRemain.add(i>9?i:"0"+i);
				}
				for(var i=1;i<=right;i++){
					blueRemain.add(i>9?i:"0"+i);
				}
				for(var i=0;i<redSet.size();i++){
					redRemain.remove(redSet.get(i));
				}
				for(var i=0;i<blueSet.size();i++){
					blueRemain.remove(blueSet.get(i));
				}
				remainArea.value=redRemain.toArray().toString()+"|"+blueRemain.toArray().toString();
			}
			filter.onclick=filterAction;
			/*
				从hashSet的元素个数中随机抽取num个元素
			*/
			function getIndexs(hashSet,num){
				var indexs=new HashSet();
				if(hashSet.size() ==1) return indexs;
				if(hashSet.size()<num) num=hashSet.size();
				while(indexs.size()!=num){
					indexs.add( (Math.floor(Math.random()*100)+1)%hashSet.size());
				}
				var obj=[];
				for( i in indexs.toArray()){
					obj.push(hashSet.get(indexs.toArray()[i]));
				}
				return obj.sort();
			}	
			function pac(n,m){
				//计算从n中选m个数有多少种排列组合法 C(n,m)=n!/m!(n-m)!
				if(n<m) return;
				var nj=n;
				for(var i=n-1;i>1;i--){
					nj*=i;
				}
				var mj=m;
				for(var i=m-1;i>1;i--){
					mj*=i;
				}
				var nmj=n-m;
				for(var i=n-m-1;i>1;i--){
					nmj*=i;
				}
				return nj/(mj*nmj);
			}
			document.getElementById("randomSelect").onclick=function(){
				var value=this.value;
				var typeValue=$(":radio[checked]").attr("value");
				var leftNum=$("#left").val();				
				var rightNum=$("#right").val();				
				var str="";
				str=initCounts(value,leftNum,rightNum); 				 
				document.getElementById("randomArea").value=str;
				
			}
			$("#leftSrc").bind('change',function(){
				this.value=$.trim(this.value);
			});
			function initCounts(rows,left,right){
				var str=[];
				for(var i=0;i<rows;i++){
					str.push(getIndexs(redSet, left));
					str.push("|");
					str.push(getIndexs(blueSet,right));
					str.push("\n");					
				}
				return str.join("");
			}
		}